package com.android.baselibrary.recycler

/*
abstract class BaseAdapter<T>
    (@LayoutRes private val layoutId: Int = 0) : RecyclerView.Adapter<BaseViewHolder>() {

    private var mRecyclerManager: RecyclerView.LayoutManager? = null

    //条目点击带ViewHolder
    private var mItemViewHolderClick: ((Int, BaseViewHolder) -> Unit?)? = null

    //条目点击不带ViewHolder
    private var mItemClick: ((Int) -> Unit?)? = null

    //条目点击带View
    private var mItemViewClick: ((View, Int) -> Unit?)? = null

    //多选的最终回调
    private var mItemMultipleChoiceListener: ((List<T>) -> Unit?)? = null

    //多选的数据集合
    private var mMultipleChoiceList: MutableList<T> = arrayListOf()

    //上下文
    private var mContext: Context? = null

    //数据集合
    private var mList: MutableList<T> = arrayListOf()

    //绑定的RecyclerView
    private var mRecyclerView: RecyclerView? = null

    //添加的头集合
    private var mHeaderLayoutList = ArrayList<Int>()

    //添加的尾集合
    private var mFooterLayoutList = ArrayList<Int>()

    //多条目布局
    val mLayouts: SparseArray<Int> by lazy(LazyThreadSafetyMode.NONE) { SparseArray() }

    //是否展示空的视图
    private var mIsEmpty = false

    //是否展示错误的视图
    private var mIsError = false

    //是否展示加载中的视图
    private var mIsLoading = false

    //空的视图View
    private var mEmptyView: View? = null

    //错误的视图View
    private var mErrorView: View? = null

    //加载视图View
    private var mLoadingView: View? = null

    private var mItemDecorationAt: RecyclerView.ItemDecoration? = null

    */
/**
     * 设置侧滑菜单跟布局是否偏移，item背景圆角且实现左滑到屏幕边缘时使用
     *//*

    private var isSwiperLayoutOffset = false

    */
/**
     * 侧滑菜单跟布局圆角半径
     *//*

    private var swiperLayoutCornerRadius = -1

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:选中的条目索引
     *//*

    var mCheckPosition = -1

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:上一个选中的索引
     *//*

    var mOldCheckPosition = -1

    @SuppressLint("ClickableViewAccessibility")
    override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
        super.onAttachedToRecyclerView(recyclerView)
        mContext = recyclerView.context
        mRecyclerView = recyclerView

        if (mRecyclerView?.itemDecorationCount!! > 0) {
            mItemDecorationAt = mRecyclerView?.getItemDecorationAt(0)
        }

        //支持拖拽或者滑动删除，方可进行初始化
        if (mIsDrag || mIsSlideDelete) {
            bindItemTouchHelper()
        }

        mRecyclerManager = mRecyclerView?.layoutManager
    }


    override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
        super.onDetachedFromRecyclerView(recyclerView)
        mRecyclerView = null

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        val view: View = if (mIsEmpty || mIsError || mIsLoading) {
            //展示为空的视图
            LayoutInflater.from(mContext)
                .inflate(R.layout.layout_list_empty_or_error, parent, false)
        } else {
            if (isMultiple()) {
                //多条目
                val layoutId = mLayouts[viewType]
                if (layoutId != null) {
                    LayoutInflater.from(mContext).inflate(layoutId, parent, false)
                } else {
                    LayoutInflater.from(mContext).inflate(viewType, parent, false)
                }
            } else {
                if (getIsSlideDelete()) {
                    //如果是侧滑删除
                    val slideDelete = LayoutInflater.from(mContext)
                        .inflate(R.layout.layout_list_slide_delete, parent, false)

                    if (swiperLayoutCornerRadius > -1) {
                        val swipeContainer = slideDelete.findViewById<SwipeMenuView>(R.id.swipe_menu_layout)

                        if(isSwiperLayoutOffset){
                            //设置左边margin为负值, 以实现左滑时到父布局边缘为止依然显示item view
                            val params = swipeContainer.layoutParams as ViewGroup.MarginLayoutParams
                            params.marginStart = -swiperLayoutCornerRadius
                            swipeContainer.layoutParams = params
                        }

                        //设置圆角
                        swipeContainer.outlineProvider = object : ViewOutlineProvider() {
                            override fun getOutline(view: View, outline: Outline) {
                                outline.setRoundRect(
                                    0,
                                    0,
                                    view.width,
                                    view.height,
                                    swiperLayoutCornerRadius.toFloat()
                                )
                            }
                        }
                        swipeContainer.clipToOutline = true
                    }

                    //获取用于加载子类布局的父View
                    val parentView = slideDelete.findViewById<LinearLayout>(R.id.ll_content)
                    //获取子类视图
                    val childView = LayoutInflater.from(mContext).inflate(viewType, parent, false)
                    //追加View
                    parentView.addView(childView)
                    val height = childView.layoutParams.height
                    //设置高度
                    val layoutSlide = slideDelete.findViewById<LinearLayout>(R.id.ll_slide)
                    val slideLayout =
                        LayoutInflater.from(mContext).inflate(getSlideLayout(), parent, false)

                    layoutSlide.addView(slideLayout)
                    layoutSlide.layoutParams.height = height
                    slideDelete
                } else {
                    //否则不是
                    LayoutInflater.from(mContext).inflate(viewType, parent, false)
                }

            }
        }

        return BaseViewHolder(view)
    }

    open fun getSlideLayout(): Int {
        return R.layout.layout_list_slide_item
    }

    open fun setSwiperLayoutOffset(isClipItemView:Boolean){
        this.isSwiperLayoutOffset = isClipItemView
    }

    */
/**
     * 设置滑动布局圆角半径
     * @param radius Int ex: dp2px(8)
     *//*

    open fun setSwiperLayoutCornerRadius(radius:Int){
        this.swiperLayoutCornerRadius = radius
    }

    override fun getItemViewType(position: Int): Int {
        super.getItemViewType(position)
        return getAdapterLayout(position)//以当前的layout做为类型区分
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:是否需要单选更新
     *//*

    open fun isNotifySingleChoice(): Boolean {
        return false
    }


    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:是否需要多选更新
     *//*

    open fun isNotifyMultipleChoice(): Boolean {
        return false
    }


    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:是否是多条目
     *//*

    open fun isMultiple(): Boolean {
        return false
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:多条目返回的类型
     *//*

    open fun getMultipleItemViewType(position: Int): Int {
        return 0
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:获取传递的最终的layout
     *//*

    private fun getAdapterLayout(position: Int): Int {
        if (mIsEmpty || mIsError || mIsLoading) {
            return position
        }
        //头View
        if (mHeaderLayoutList.isNotEmpty() && position < mHeaderLayoutList.size) {
            return mHeaderLayoutList[position]
        }
        //尾部
        val listSize = mList.size - mFooterLayoutList.size - 1
        if (position > listSize) {
            val index = mList.size - 1 - position
            val footerIndex = mFooterLayoutList.size - 1 - index
            return mFooterLayoutList[footerIndex]
        }

        if (isMultiple()) {
            return getMultipleItemViewType(position)
        }

        var layoutRes = layoutId
        val layout = getLayoutId()

        if (layoutRes == 0 && layout != 0) {
            layoutRes = layout
        }

        return layoutRes
    }


    override fun getItemCount(): Int {
        if (mIsEmpty || mIsError || mIsLoading) {
            //如果数据为空或者展示错误的视频
            return 1
        }
        return mList.size
    }


    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:初始化数据添加
     *//*

    fun setList(list: MutableList<T>?) {
        if (list != null) {
            mList = list
        } else {
            mList.clear()
        }

        clearDefault()

        notifyDataSetChanged()
    }

    private fun clearDefault() {
        if (mList.isNotEmpty()) {

            if (mIsLoading || mIsEmpty || mIsError) {
                addViewItemDecoration()
            }
            //还原管理器
            mRecyclerView?.layoutManager = mRecyclerManager
            //不为空
            mIsLoading = false
            mIsEmpty = false
            mIsError = false
        }
    }

    fun setList(list: ArrayList<T>?) {
        if (list != null) {
            mList = list
        } else {
            mList.clear()
        }
        clearDefault()
        notifyDataSetChanged()
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:追加数据
     *//*

    fun addData(list: MutableList<T>) {
        val position = mList.size
        //这里要判断是否有尾，如果有尾，那么索引就要上移
        if (mFooterLayoutList.isEmpty()) {
            mList.addAll(list)
        } else {
            mList.addAll((position - mFooterLayoutList.size), list)
        }

        val endPosition = mList.size
        //从指定位置刷新
        notifyItemRangeChanged(position, endPosition)
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:追加数据
     *//*

    fun addData(t: T) {
        val position = mList.size
        //这里要判断是否有尾，如果有尾，那么索引就要上移
        if (mFooterLayoutList.isEmpty()) {
            mList.add(t)
        } else {
            mList.add((position - mFooterLayoutList.size), t)
        }
        val endPosition = mList.size
        //从指定位置刷新
        notifyItemRangeChanged(position, endPosition)
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:移除数据
     * @param position 索引
     *//*

    fun removeData(position: Int) {
        //移除数据必须在去除头和尾部之间
        val headerSize = mHeaderLayoutList.size
        val footerSize = mFooterLayoutList.size
        val listHeaderSize = mList.size - headerSize//除去头部还剩下的数据
        val listFooterSize = mList.size - footerSize//除去尾部还剩下的数据
        val index = position + headerSize
        if (listHeaderSize > 0 && index < listFooterSize) {
            mList.removeAt(index)
            notifyItemRemoved(index)
        } else {
            toast("没数据可删了")
        }

    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:获取传递的集合
     *//*

    fun getList(): MutableList<T> {
        return mList
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:获取对应的数据对象
     *//*

    fun getModel(position: Int): T {
        return mList[position]
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:子类需要传递的layout
     *//*

    open fun getLayoutId(): Int {
        return 0
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:添加头View
     * @param headerView View
     * @param refresh  true 刷新  false 不刷新
     *//*

    fun addHead(headerView: View, refresh: Boolean = false) {
        if (mList.isNotEmpty()) {
            val sourceLayoutResId = headerView.sourceLayoutResId
            mList.add(0, mList[0])
            mHeaderLayoutList.add(0, sourceLayoutResId)//追加资源
            if (refresh) {
                notifyItemInserted(0)
            }
        } else {
            toast("集合数据为空，不能添加头部View")
        }
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:添加头View  以layout id的方式
     * @param layoutId layout
     * @param refresh  true 刷新  false 不刷新
     *//*

    fun addHead(layoutId: Int, refresh: Boolean = false) {
        addHead(View.inflate(mContext, layoutId, null), refresh)
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:移除头View
     * @param position 移除的头部索引
     *//*

    fun removeHead(position: Int = 0) {
        if (position < mHeaderLayoutList.size) {
            //进行移除
            mList.removeAt(position)
            mHeaderLayoutList.removeAt(position)
            notifyItemRemoved(position)
        } else {
            toast("没有头部View了")
        }
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:追加尾View
     *//*

    fun addFoot(footerView: View, refresh: Boolean = false) {
        if (mList.isNotEmpty()) {
            val sourceLayoutResId = footerView.sourceLayoutResId
            mList.add(mList[0])
            mFooterLayoutList.add(sourceLayoutResId)//追加资源
            if (refresh) {
                notifyItemInserted(mList.size - 1)
            }
        } else {
            toast("集合数据为空，不能添加尾部View")
        }
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:追加尾View 以layout id的方式
     *//*

    fun addFoot(layoutId: Int, refresh: Boolean = false) {
        addFoot(View.inflate(mContext, layoutId, null), refresh)
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:移除尾部View
     * @param position 移除的尾部索引
     *//*

    fun removeFooter(position: Int = 0) {
        if (mFooterLayoutList.isNotEmpty() && position < mFooterLayoutList.size) {
            //删除最后一个
            mFooterLayoutList.removeAt(mFooterLayoutList.size - 1 - position)
            mList.removeAt(mList.size - 1 - position)
            notifyItemRemoved(mList.size - position)
        } else {
            toast("没有尾部View了")
        }
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        try {
            if (mIsEmpty || mIsError || mIsLoading) {
                //设置空或者错误页面
                val layoutEmpty = holder.findView<FrameLayout>(R.id.layout_empty)
                layoutEmpty.removeAllViews()
                if (mIsLoading) {
                    //如果是loading 后期再更改
                    layoutEmpty.addView(mLoadingView)
                } else {
                    layoutEmpty.addView(if (mIsEmpty) mEmptyView else mErrorView)
                }

            } else if (mHeaderLayoutList.isNotEmpty() && position < mHeaderLayoutList.size) {
                //头
                dataOperationHead(holder, position)
            } else if (mFooterLayoutList.isNotEmpty() && position > (mList.size - mFooterLayoutList.size - 1)) {
                //尾
                dataOperationFoot(holder, position)
            } else {
                //正常视图
                val bean = mList[position]

                holder.itemView.setOnClickListener {
                    if (mOldCheckPosition != mCheckPosition) {
                        mOldCheckPosition = mCheckPosition
                    }
                    mCheckPosition = position

                    //单选更新
                    if (isNotifySingleChoice()) {
                        notifySingleChoice()
                    }

                    //多选更新
                    if (isNotifyMultipleChoice()) {
                        val t = getList()[position]
                        if (t is BaseMultipleChoiceBean) {
                            t.isChoiceItem = !t.isChoiceItem
                            if (t.isChoiceItem) {
                                mMultipleChoiceList.add(t)
                            } else {
                                mMultipleChoiceList.remove(t)
                            }
                            //回调
                            mItemMultipleChoiceListener?.let {
                                it(mMultipleChoiceList)
                            }
                            notifyItemChanged(position)
                        }
                    }

                    //条目点击事件
                    mItemClick?.let {
                        it(if (mIsDrag) holder.adapterPosition else position)
                    }
                    //条目点击事件
                    mItemViewClick?.let {
                        it(holder.itemView, if (mIsDrag) holder.adapterPosition else position)
                    }
                    mItemViewHolderClick?.let {
                        it(if (mIsDrag) holder.adapterPosition else position, holder)
                    }
                }

                dataOperation(holder, bean, position)
            }

        } catch (e: Exception) {
            bindViewHolderError(e)
            e.printStackTrace()
        }
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:增加获取异常信息
     *//*

    open fun bindViewHolderError(e: Exception) {

    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:单选更新
     *//*

    private fun notifySingleChoice() {
        notifyItemChanged(mCheckPosition)
        notifyItemChanged(mOldCheckPosition)
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:绑定尾
     *//*

    open fun dataOperationFoot(holder: BaseViewHolder, position: Int) {

    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:绑定头
     *//*

    open fun dataOperationHead(holder: BaseViewHolder, position: Int) {

    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:数据操作
     *//*

    abstract fun dataOperation(holder: BaseViewHolder, t: T?, position: Int)

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:设置条目点击事件
     *//*

    fun setOnItemClickListener(itemClick: (position: Int) -> Unit) {
        mItemClick = itemClick
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:设置条目点击事件
     *//*

    fun setOnItemViewClickListener(itemViewClick: (view: View, position: Int) -> Unit) {
        mItemViewClick = itemViewClick
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:多选的最终回调
     *//*

    fun setOnMultipleChoiceListener(itemMultipleChoiceListener: (list: List<T>) -> Unit) {
        mItemMultipleChoiceListener = itemMultipleChoiceListener
    }


    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:设置条目点击事件 带ViewHolder
     *//*

    fun setOnItemViewHolderClickListener(itemClick: (position: Int, holder: BaseViewHolder) -> Unit) {
        mItemViewHolderClick = itemClick
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:获取上下文
     *//*

    fun getContext(): Context? {
        return mContext
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:弹出提示
     *//*

    private fun toast(msg: String) {
        Toast.makeText(mContext, msg, Toast.LENGTH_SHORT).show()
    }


    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:添加空的布局
     *//*

    fun addEmptyView(layoutId: Int) {
        addEmptyView(View.inflate(mContext, layoutId, null))
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:添加空的View
     *//*


    fun addEmptyView(view: View) {
        mEmptyView = view
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:添加空的布局
     *//*

    fun addLoadingView(layoutId: Int) {
        addLoadingView(View.inflate(mContext, layoutId, null))
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:添加空的View
     *//*


    fun addLoadingView(view: View) {
        mLoadingView = view
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:添加错误View
     *//*

    fun addErrorView(view: View) {
        mErrorView = view
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:添加空的布局
     *//*

    fun addErrorView(layoutId: Int) {
        addErrorView(View.inflate(mContext, layoutId, null))
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:展示错误视图
     *//*

    fun showErrorView() {
        if (mErrorView == null) {
            throw NullPointerException("请确定是否执行了addErrorView方法？")
        }

        if (!mIsError) {
            removeViewItemDecoration()
        }
        mIsError = true
        mIsEmpty = false
        mIsLoading = false

        //改变管理器
        mRecyclerView?.layoutManager = LinearLayoutManager(getContext())

        notifyDataSetChanged()
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:隐藏错误视图
     *//*

    fun hintErrorView() {
        if (mIsError) {
            addViewItemDecoration()
        }
        mIsError = false
        //还原管理器
        mRecyclerView?.layoutManager = mRecyclerManager
        notifyDataSetChanged()
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:展示loading视图
     *//*

    fun showLoadingView() {
        if (mLoadingView == null) {
            throw NullPointerException("请确定是否执行了addLoadingView方法？")
        }
        if (!mIsLoading) {
            removeViewItemDecoration()
        }
        mIsLoading = true
        mIsError = false
        mIsEmpty = false

        //改变管理器
        mRecyclerView?.layoutManager = LinearLayoutManager(getContext())

        notifyDataSetChanged()
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:隐藏Loading视图
     *//*

    fun hintLoadingView() {
        if (mIsLoading) {
            addViewItemDecoration()
        }
        mIsLoading = false
        //还原管理器
        mRecyclerView?.layoutManager = mRecyclerManager
        notifyDataSetChanged()
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:显示空的布局
     *//*

    fun showEmptyView() {
        if (mEmptyView == null) {
            throw NullPointerException("请确定是否执行了addEmptyView方法？")
        }
        if (!mIsEmpty) {
            //移除线
            removeViewItemDecoration()
        }
        mIsEmpty = true
        mIsLoading = false
        mIsError = false
        //改变管理器
        mRecyclerView?.layoutManager = LinearLayoutManager(getContext())

        notifyDataSetChanged()
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:隐藏空的布局
     *//*

    fun hintEmptyView() {
        if (mIsEmpty) {
            //重新添加线
            addViewItemDecoration()
        }
        mIsEmpty = false
        //还原管理器
        mRecyclerView?.layoutManager = mRecyclerManager
        notifyDataSetChanged()
    }


    private fun removeViewItemDecoration() {
        mItemDecorationAt?.let {
            mRecyclerView?.removeItemDecoration(it)
        }
    }

    private fun addViewItemDecoration() {
        mItemDecorationAt?.let {
            mRecyclerView?.addItemDecoration(it)
        }
    }


    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:绑定helper
     *//*

    private fun bindItemTouchHelper() {
        val itemTouchHelper = ItemTouchHelper(object : ItemTouchHelper.Callback() {
            */
/**
             * 滑动或者拖拽的方向，上下左右
             * @param recyclerView 目标RecyclerView
             * @param viewHolder 目标ViewHolder
             * @return 方向
             *//*

            */
/**
             * 滑动或者拖拽的方向，上下左右
             * @param recyclerView 目标RecyclerView
             * @param viewHolder 目标ViewHolder
             * @return 方向
             *//*

            override fun getMovementFlags(
                recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder
            ): Int {

                val list = getList()
                val position = viewHolder.adapterPosition
                val bean = list[position]
                //禁止拖拽
                if (bean is BaseNoDragBean && !bean.isDrag) {
                    return 0
                }
                //禁止哪些拖拽
                if (mNoDragArray != null && mNoDragArray?.contains(viewHolder.adapterPosition)!!) {
                    return 0
                }
                //设置拖拽方向
                return makeMovementFlags(mDragDirection, mSlideDirection)
            }


            */
/**
             * 拖拽item移动时产生回调
             * @param recyclerView 目标RecyclerView
             * @param viewHolder 拖拽的item对应的viewHolder
             * @param target 拖拽目的地的ViewHOlder
             * @return 是否消费拖拽事件
             *//*

            */
/**
             * 拖拽item移动时产生回调
             * @param recyclerView 目标RecyclerView
             * @param viewHolder 拖拽的item对应的viewHolder
             * @param target 拖拽目的地的ViewHOlder
             * @return 是否消费拖拽事件
             *//*

            override fun onMove(
                recyclerView: RecyclerView,
                viewHolder: RecyclerView.ViewHolder,
                target: RecyclerView.ViewHolder
            ): Boolean {
                //得到当拖拽的viewHolder的Position
                val fromPosition = viewHolder.adapterPosition
                val toPosition = target.adapterPosition

                //处理拖拽事件
                if (getList().isEmpty()) {
                    return false
                }
                val bean = getList()[toPosition]

                //固定不能换位置
                if (bean is BaseNoDragBean && bean.isRegular) {
                    return false
                }

                return if (fromPosition >= 0 && fromPosition < getList().size && toPosition >= 0 && toPosition < getList().size) {
                    //交换数据位置
                    //Collections.swap(getList(), fromPosition, toPosition)
                    //根据滑动方向，交换数据
                    if (fromPosition < toPosition) {
                        for (index in fromPosition until toPosition) {
                            Collections.swap(getList(), index, index + 1)
                        }
                    } else {
                        for (index in fromPosition downTo toPosition + 1) {
                            Collections.swap(getList(), index, index - 1)
                        }
                    }
                    notifyItemMoved(fromPosition, toPosition)
                    true
                } else {
                    false
                }
            }

            override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
                //侧滑删除
                val position = viewHolder.adapterPosition
                notifyItemRemoved(position)
                mList.removeAt(position)
            }

            */
/**
             * AUTHOR:AbnerMing
             * INTRODUCE:拖拽是否可用
             *//*

            */
/**
             * AUTHOR:AbnerMing
             * INTRODUCE:拖拽是否可用
             *//*

            override fun isLongPressDragEnabled(): Boolean {
                return mIsDrag
            }

            */
/**
             * AUTHOR:AbnerMing
             * INTRODUCE:是否可以滑动删除
             *//*

            */
/**
             * AUTHOR:AbnerMing
             * INTRODUCE:是否可以滑动删除
             *//*

            override fun isItemViewSwipeEnabled(): Boolean {
                return mIsSlideDelete
            }

        })


        itemTouchHelper.attachToRecyclerView(mRecyclerView)
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:是否支持拖拽
     *//*

    private var mIsDrag = false

    fun isDrag() {
        mIsDrag = true
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:哪些不能拖动
     *//*

    private var mNoDragArray: IntArray? = null
    fun setRecyclerNoDrag(dragArray: IntArray) {
        mNoDragArray = dragArray
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:是否支持滑动删除
     *//*

    private var mIsSlideDelete = false
    fun isSlideDelete() {
        mIsSlideDelete = true
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:滑动删除方向，默认只有左边
     *//*

    private var mSlideDirection = ItemTouchHelper.LEFT

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:设置滑动为左右方向
     *//*

    fun setSlideLeftOrRight() {
        mSlideDirection = ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:单独设置方向
     *//*

    fun setSlideDirection(direction: Int) {
        mSlideDirection = direction
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:设置拖拽方向，默认上下左右
     *//*

    private var mDragDirection =
        ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT or ItemTouchHelper.UP or ItemTouchHelper.DOWN

    fun setDragDirection(direction: Int) {
        mDragDirection = direction
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:设置拖拽为上下方向
     *//*

    fun setDragUpOrDown() {
        mDragDirection = ItemTouchHelper.UP or ItemTouchHelper.DOWN
    }

    */
/**
     * AUTHOR:AbnerMing
     * INTRODUCE:是否是侧滑按钮的形式删除
     *//*

    open fun getIsSlideDelete(): Boolean {
        return false
    }

}
*/
